import { getUserAccountAPI, getUserCodeLoginAPI } from '@/api'
export default {
  namespaced: true,
  state: () => ({
    profile: {
      id: '',
      avatar: '',
      nickname: '',
      account: '',
      mobile: '',
      token: ''
    }
  }),
  getters: {},
  mutations: {
    setUser(state, user) {
      state.profile = user
    }
  },
  actions: {
    async getUserAccountAction(context, user) {
      try {
        const res = await getUserAccountAPI(user)
        console.log(res)
        context.commit('setUser', res.result)
      } catch (err) {
        const msg = err.response.data.message || '登录失败'
        throw new Error(msg)
      }
    },
    async getUserMobileAction(context, mobile) {
      try {
        const res = await getUserCodeLoginAPI(mobile)
        console.log(res)
        context.commit('setUser', res.result)
      } catch (err) {
        const msg = err.response.data.message || '登录失败'
        throw new Error(msg)
      }
    }
  }
}
